package com.gtja.beoms.service.impl;
import com.gtja.beoms.dao.IFileDao;
import com.gtja.beoms.dto.FileBO;
import com.gtja.beoms.pojo.FileDO;
import com.gtja.beoms.service.IFileService;
import com.gtja.beoms.utils.ModelConvertUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  文件Service
 * </p>
 *
 * @author hudongling
 * @version 1.0.0
 * @date 2020/3/17
 */
@Service
@RequiredArgsConstructor
public class FileServiceImpl implements IFileService {

    private final IFileDao fileDao;

    @Override
    public String reFileName(String origName, String creator) {
        if (StringUtils.isBlank(creator)){
            return System.currentTimeMillis()+"_" + (int)(Math.random() * 100)+"."+origName.substring(origName.lastIndexOf(".")+1);
        }
        return creator + "_" + System.currentTimeMillis()+"_" + (int)(Math.random() * 100)+"."+origName.substring(origName.lastIndexOf(".")+1);
    }

    @Override
    public int insertUploadInfoRecord(FileBO fileBO) {
        FileDO fileDO = ModelConvertUtil.copy(fileBO, FileDO.class);
        return fileDao.insertUpEmfileRecord(fileDO);
    }


}
